#ifndef CONNECTOR_H
#define CONNECTOR_H

#include <QObject>
#include <QTcpServer>
#include "connection.h"
/**
 * 服务端连接器，接收客户端的连接
 * @brief The Connector class
 */
class Connector : public QTcpServer
{
    Q_OBJECT
public:
    /**
     * 构造函数
     * @brief Connector
     * @param port 端口
     * @param parent
     */
    explicit Connector(uint16_t port, QObject * parent);
    ~Connector() override;
    /**
     * 新的连接到达自动调用该函数
     * @brief incomingConnection
     * @param handle
     */
    void incomingConnection(qintptr handle) override;

    /**
     * 开始监听
     * @brief startListen
     * @return
     */
    bool startListen();
signals:
    /**
     * 发信号 新的连接
     * @brief newConnection
     * @param conn
     */
    void newConnection(Connection *conn);
private:
    uint16_t port;
};

#endif // CONNECTOR_H
